home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 476-500 / disk_496 / availmem / availmem.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  137 lines

  1. /*------------------------- AvailMem V1.12 ----------------------------*/
  2. /*Written and copyright ©1988-1991 by Dave Schreiber. All rights       */
  3. /*reserved.  This program may not be sold, but reasonable charges for  */
  4. /*media, duplication, shipping/handling, etc. are permitted.           */
  5. /*---------------------------------------------------------------------*/
  6. /*Keeps a running count of the amount of FAST, CHIP, and total memory  */
  7. /*free.  Updates every .7 seconds. Compiled with SAS/C V5.10.           */
  8. /*To compile:                                   */
  9. /*     1> lc -v -Lcd AvailMem                           */
  10. /*----------------------------- Enjoy ---------------------------------*/
  11. /*Version history:                               */
  12. /* 1.12 - Fixed a problem with non-8pt default fonts under 2.0           */
  13. /* 1.10 - Added a counter of the largest block free for FAST, CHIP, and*/
  14. /*      total memory                               */
  15. /* 1.03 - First release to the public.    Included on Fred Fish disk #285*/
  16. /*---------------------------------------------------------------------*/
  17.  
  18.  
  19. /*Standard #include files*/
  20. #include <exec/types.h>
  21. #include <exec/exec.h>
  22. #include <intuition/intuition.h>
  23. #include <intuition/intuitionbase.h>
  24. #include <graphics/gfxbase.h>
  25.  
  26. /*Window and IntuiText definitions*/
  27. #include "AvailMem.h"
  28.  
  29. struct IntuitionBase *IntuitionBase;   /*Library base pointers*/
  30. struct GfxBase *GfxBase;
  31.  
  32. void MainLoop();
  33. void MakeString();
  34. void InitIntuiText(UWORD add,UWORD addX);
  35.  
  36. #define Rp Wdw->RPort
  37.  
  38.      /*Using _main() keeps AmigaDOS from opening an extra */
  39. _main()  /*console window when AvailMem is run from Workbench.*/
  40. {
  41.    if((IntuitionBase=(struct IntuitionBase *)   /*Open Intuition*/
  42.      OpenLibrary("intuition.library",0))==NULL)
  43.       exit(10);
  44.                   /*Open Graphics*/
  45.    if((GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0))==NULL)
  46.    {
  47.       CloseLibrary(IntuitionBase); /*Like it really matters...*/
  48.       exit(20);
  49.    }
  50.  
  51.    MainLoop();
  52.  
  53.    CloseLibrary(GfxBase);     /*Close the libraries*/
  54.    CloseLibrary(IntuitionBase);
  55.    return(0);
  56. }
  57.  
  58. void MainLoop()   /*The main loop*/
  59. {
  60.    struct Window *Wdw;    /*Window pointer*/
  61.    struct Screen *WBScreen;
  62.    ULONG c,f;
  63.    UWORD add1,add2,addX;
  64.  
  65.    WBScreen=IntuitionBase->ActiveScreen;
  66.  
  67.    /*Get font size information*/
  68.    add1 = WBScreen->Font->ta_YSize-8;
  69.    add2 = GfxBase->DefaultFont->tf_YSize-8;
  70.    addX = GfxBase->DefaultFont->tf_XSize-8;
  71.  
  72.    /*Change window dimensions to fit default fonts*/
  73.    NewWindowStructure1.Height+=add1+5*add2;
  74.    NewWindowStructure1.Width=30*(8+addX);
  75.  
  76.    InitIntuiText(add2,addX);  /*Initialize the IntuiText structures*/
  77.  
  78.                   /*Open the window*/
  79.    if((Wdw=(struct Window *)OpenWindow(&NewWindowStructure1))==NULL)
  80.       exit(30);
  81.  
  82.    Delay(10);
  83.  
  84.    PrintIText(Rp,&IText1,-6,2+add1);
  85.  
  86.    /*while the close gadget wasn't pressed...*/
  87.    while( ( GetMsg(Wdw->UserPort) ) == NULL)
  88.       {  /*For each possibility, get the memory count, convert it to text,
  89.      /*put it into the appropriate intuitext structure,*/
  90.  
  91.       c=AvailMem(MEMF_LARGEST|MEMF_CHIP);
  92.       f=AvailMem(MEMF_LARGEST|MEMF_FAST);
  93.       MakeString(IText12.IText,(c < f) ? f : c);
  94.       MakeString(IText11.IText,c);
  95.       MakeString(IText10.IText,f);
  96.  
  97.       c=AvailMem(MEMF_CHIP);
  98.       f=AvailMem(MEMF_FAST);
  99.       MakeString(IText9.IText,f);
  100.       MakeString(IText8.IText,c);
  101.       MakeString(IText7.IText,f+c);
  102.  
  103.       PrintIText(Rp,&IText7,-6,2+add1); /*and print it*/
  104.       Delay(35);    /*Wait for .7 seconds, then do the whole thing again*/
  105.       }
  106.    CloseWindow(Wdw);    /*Close the window*/
  107. }
  108.  
  109. void MakeString(string,amt) /*Convert amt to a string, put into 'string'*/
  110. char *string;            /*and pad out with spaces*/
  111. ULONG amt;
  112. {
  113.    BYTE c;
  114.    stcu_d(string,amt,8);   /*Convert number into text*/
  115.    for(c=strlen(string);c<8;c++)
  116.       string[c]=' ';       /*Pad out with spaces*/
  117.  
  118.    string[8]=NULL;       /*And terminate with a NULL*/
  119. }
  120.  
  121.  
  122. /*Initializes the IntuiText structures (spaces them according to the */
  123. /*default fonts).*/
  124. void InitIntuiText(UWORD add,UWORD addX)
  125. {
  126.    IText5.TopEdge=(IText6.TopEdge+=add);
  127.    IText1.TopEdge=IText9.TopEdge=(IText10.TopEdge+=(add*2));
  128.    IText2.TopEdge=IText8.TopEdge=(IText11.TopEdge+=(add*3));
  129.    IText3.TopEdge=IText7.TopEdge=(IText12.TopEdge+=(add*4));
  130.  
  131.    IText5.LeftEdge=IText9.LeftEdge=IText8.LeftEdge=
  132.      (IText7.LeftEdge+=addX*7);
  133.    IText6.LeftEdge=IText10.LeftEdge=IText11.LeftEdge=
  134.      (IText12.LeftEdge+=addX*17);
  135. }
  136.  
  137.